package cn.acewill.yxd.yunxundian.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.bumptech.glide.Glide;

import java.util.List;

import cn.acewill.yxd.yunxundian.R;

/**
 * Created by AAA on 2017/4/24.
 */

public class AddPhotoAdapter extends BaseAdapter{

    private Context context;
    private List<String> list;

    public AddPhotoAdapter(Context context, List<String> list){
        this.context=context;
        this.list=list;
    }


    @Override
    public int getCount() {
        return list==null?1:list.size()+1;
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
    public void setListData(List<String> list){
        this.list=list;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if(convertView==null){
            convertView= LayoutInflater.from(context).inflate(R.layout.image_submitview,parent,false);
            holder=new ViewHolder();
            holder.ItemImage= (ImageView) convertView.findViewById(R.id.ItemImage);
            convertView.setTag(holder);
        }else{
            holder= (ViewHolder) convertView.getTag();
        }
        holder.ItemImage.setScaleType(ImageView.ScaleType.CENTER);
        if (position==0){
            holder.ItemImage.setImageResource(R.mipmap.icon_add_photo);
        }else{
           // holder.ItemImage.setImageURI(Uri.parse(list.get(position)));
            Glide.with(context).load(list.get(position-1)).thumbnail(0.1f).into(holder.ItemImage);//显示缩略图
        }

        return convertView;
    }

    class ViewHolder{
        ImageView ItemImage;
    }
}
